package com.mtask.web.controller;

import com.mtask.common.dto.TaskGroupDTO;
import com.mtask.common.dto.TaskGroupResponseDTO;
import com.mtask.web.service.GroupService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RequestMapping("/group")
@RestController
public class GroupController {

    @Resource
    private GroupService groupService;

    @PostMapping
    public void save(@RequestBody @Valid TaskGroupDTO dto) {
        groupService.save(dto);
    }


    @PostMapping("/all")
    public Page<TaskGroupResponseDTO> findAll(@RequestBody PageRequest pageable) {
        return groupService.findAll(pageable);
    }

    @DeleteMapping("/{id}")
    public void delete(@PathVariable Integer id) {
        groupService.deleteById(id);
    }

    @GetMapping("/{id}")
    public List<TaskGroupResponseDTO> findByPorjectId(@PathVariable Integer id) {
        return groupService.findByProjectId(id);
    }

}
